<template>
	<body-wrap :isFlex='true' :showLoading="false">
		<view class="detailtopbox">
			<image class="dimg" :src="details.imageUrl" mode="widthFix"></image>
		</view>
		<view class="detaiMain">
			<view class="title">{{details.name}}</view>
			<view class="sellnum">月售99份</view>
			<view class="priceNum">
				<view class="price">￥
					<text class="num" v-if="orderInfo.orderType==1">{{details.unitPrice}}</text>
					<text class="num" v-else-if="orderInfo.orderType==2">{{details.price}}</text>
				</view>
				<view class="numbox">
					<number-selector v-if="details.id" v-model="details.quantity"/>
				</view>
			</view>
			<view class="content" v-html="details.content"></view>
		</view>
		<template v-slot:footer>
			<bottom-btn :price='totalPrice' @onclick="goNext"/>
		</template>
	</body-wrap>
</template>

<script>
	import {defineComponent,reactive,toRefs,onMounted,getCurrentInstance,computed} from 'vue'
	import {onLoad,onShow} from '@dcloudio/uni-app'
	import { useStore } from 'vuex'
	import bodyWrap from "@/components/bodyWrap/index.vue"
	import bottomBtn from "@/components/bottomBtn/bottomBtn.vue"
	import numberSelector from "@/components/numberSelector/numberSelector.vue"
	import {getStorage} from "@/utils/common.js"
	export default defineComponent({
		components:{
			bodyWrap,
			bottomBtn,
			numberSelector
		},
		props:{
		
		},
		setup(props,context) {
			const store = useStore()
			const {proxy} = getCurrentInstance()
			
			const state = reactive({
				id:'',
				imgUrlPrefix:getApp().globalData.imgUrlPrefix,
				orderInfo:computed(()=>store.state.base.orderInfo), 
				totalPrice:0,
				details:{},
			})
			
			onLoad(options=>{
				if(options){
					options.id && (state.id = options.id)
					options.orderType && (state.orderInfo.orderType=(options.orderType || 1))
				}
				console.log("options:",options)
				state.details = store.state.base.goods.find(item => item.id == state.id)

			})
			
			state.totalPrice = computed(()=>{
				if(!state.details.id) return 0;
				let allTotal = 0
				if(state.orderInfo.orderType==1){ // 商城详情
					allTotal = (state.details.unitPrice * state.details.quantity).toFixed(2)
				}else if(state.orderInfo.orderType==2){ // 服务类详情
					allTotal = (state.details.price * state.details.quantity).toFixed(2)
				}
				return allTotal
			})
			
			onMounted(()=>{
				
			})
			
			const goNext = ()=>{
				
				uni.navigateTo({
					url:'/pages/mallBuy/mallBuy'
				})
			}
			
			return {
				...toRefs(state),
				goNext
			}
		}
	})
</script>

<style lang="scss" scoped>
	.detailtopbox{
		width: 100%;
		max-height: 500rpx;
		overflow: hidden;
		.dimg{
			display: block;
			width: 100%;
		}
	}
	.detaiMain{
		background: #fff;
		border-top-left-radius: 50rpx;
		border-top-right-radius: 50rpx;
		min-height: 1000rpx;
		margin: -50rpx 0 0 0;
		padding: 50rpx 30rpx 30rpx 30rpx;
		.title{
			font-size: 40rpx;
			line-height: normal;
			font-weight: bold;
		}
		.sellnum{
			font-size: 30rpx;
			color: #b5b5b5;
			padding: 10rpx 0 0 0;
		}
		.priceNum{
			display: flex;
			padding: 15rpx 0 0 0;
			.price{
				flex: 1;
				font-size: 30rpx;
				font-weight: 600;
				color: #ff1b1b;
				.num{
					font-size: 46rpx;
				}
			}
			.numbox{
				width: 280rpx;
			}
		}
		.content{
			font-size: 34rpx;
			font-weight: bold;
			padding: 30rpx 0 0 0;
			text-indent: 56rpx;
			line-height: 64rpx;
		}
	}
</style>
